//
//  ViewController.m
//  TomCat2
//
//  Created by dllo on 16/6/12.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property(nonatomic, retain)UIImageView *imageView;
@property(nonatomic, retain)NSMutableArray *array;
@property(nonatomic, retain)UIImageView *eat;
@property(nonatomic, retain)UIImageView *fart;
@property(nonatomic, retain)UIImageView *cymbal;
@property(nonatomic, retain)UIImageView *pie;
@property(nonatomic, retain)UIImageView *drink;
@property(nonatomic, retain)UIImageView *scratch;
@property(nonatomic, retain)UIImageView *stomach;
@property(nonatomic, retain)UIImageView *footLeft;
@property(nonatomic, retain)UIImageView *footRight;
@property(nonatomic, retain)UIImageView *angry;
@property(nonatomic, retain)UIImageView *knockout;
@end
NSInteger flag = 0;
@implementation ViewController


-(void)loadView
{
    [super loadView];


    _eat.userInteractionEnabled = YES;
    _fart.userInteractionEnabled = YES;
    _cymbal.userInteractionEnabled = YES;
    _pie.userInteractionEnabled = YES;
    _drink.userInteractionEnabled = YES;
    _scratch.userInteractionEnabled = YES;

    //初始化图片视图
    _imageView = [[UIImageView alloc]initWithFrame:self.view.frame];
    //设置出示图片
    _imageView.image = [UIImage imageNamed:@"angry_00.jpg"];
    //将图片视图添加到View
    [self.view addSubview:_imageView];
    [_imageView release];
    
    _eat = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"eat.png"]];
    _eat.frame = CGRectMake(10, 367, 60, 60);
    [self.view addSubview:_eat];
    [_eat release];
    
    _fart = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"fart.png"]];
    _fart.frame = CGRectMake(310, _eat.frame.origin.y, _eat.frame.size.width, _eat.frame.size.height);
    [self.view addSubview:_fart];
    [_fart release];
    
    _cymbal = [[UIImageView alloc]init];
    _cymbal.image = [UIImage imageNamed:@"cymbal.png"];
    _cymbal.frame = CGRectMake(_eat.frame.origin.x, _eat.frame.origin.y + _eat.frame.size.height +  50, _eat.frame.size.width, _eat.frame.size.height);
    [self.view addSubview:_cymbal];
    [_cymbal release];
    
    _pie = [[UIImageView alloc]init];
    _pie.image = [UIImage imageNamed:@"pie.png"];
    _pie.frame = CGRectMake(_fart.frame.origin.x, _cymbal.frame.origin.y, _cymbal.frame.size.width, _cymbal.frame.size.height);
    [self.view addSubview:_pie];
    [_pie release];
    
    _drink = [[UIImageView alloc]init];
    _drink.image = [UIImage imageNamed:@"drink.png"];
    _drink.frame = CGRectMake(_cymbal.frame.origin.x, _cymbal.frame.size.height + _cymbal.frame.origin.y + 50, _pie.frame.size.width, _pie.frame.size.height);
    [self.view addSubview:_drink];
    [_drink release];
    
    _scratch = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"scratch.png"]];
    _scratch.frame = CGRectMake(_pie.frame.origin.x, _drink.frame.origin.y, _drink.frame.size.width, _drink.frame.size.height);
    [self.view addSubview:_scratch];
    [_scratch release];
    
    _stomach = [[UIImageView alloc]initWithFrame:CGRectMake(125, 400, 125, 200)];
    _stomach.backgroundColor = [UIColor clearColor];
    [self.view addSubview:_stomach];
    [_stomach release];
    
    _footLeft = [[UIImageView alloc]initWithFrame:CGRectMake(190, 600, 50, 50)];
    _footLeft.backgroundColor = [UIColor clearColor];
    [self.view addSubview:_footLeft];
    [_footLeft release];
    
    _footRight = [[UIImageView alloc]initWithFrame:CGRectMake(130, 600, 50, 50)];
    _footRight.backgroundColor = [UIColor clearColor];
    [self.view addSubview:_footRight];
    [_footRight release];
    
    _angry = [[UIImageView alloc]initWithFrame:CGRectMake(250, 500, 30, 100)];
    _angry.backgroundColor = [UIColor clearColor];
    //_angry.backgroundColor = [UIColor redColor];
    [self.view addSubview:_angry];
    [_angry release];
    
    _knockout = [[UIImageView alloc]initWithFrame:CGRectMake(80, 120, 210, 200)];
    _knockout.backgroundColor = [UIColor clearColor];
    [self.view addSubview:_knockout];
    [_knockout release];

}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    //为imageview准备素材
    //初始化数组
    
    // Do any additional setup after loading the view, typically from a nib.
    
    //1.将图标文件里的图标素材添加到View上
    
    
    //2.点击不同图标实现相应的动画

UITapGestureRecognizer *tapToEat = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Eat)];
[_eat addGestureRecognizer:tapToEat];
_eat.userInteractionEnabled = YES;
[tapToEat release];

UITapGestureRecognizer *tapToFart = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Fart)];
[_fart addGestureRecognizer:tapToFart];
_fart.userInteractionEnabled = YES;
[tapToFart release];

UITapGestureRecognizer *tapToCymbal = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Cymbal)];
[_cymbal addGestureRecognizer:tapToCymbal];
_cymbal.userInteractionEnabled = YES;
[tapToCymbal release];

UITapGestureRecognizer *tapToPie = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Pie)];
[_pie addGestureRecognizer:tapToPie];
_pie.userInteractionEnabled = YES;
[tapToPie release];


UITapGestureRecognizer *tapToDrink = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Drink)];
[_drink addGestureRecognizer:tapToDrink];
_drink.userInteractionEnabled = YES;
[tapToDrink release];

UITapGestureRecognizer *tapToScratch = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Scratch)];
[_scratch addGestureRecognizer:tapToScratch];
_scratch.userInteractionEnabled = YES;
[tapToScratch release];

UITapGestureRecognizer *tapToStomach = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Stomach)];
[_stomach addGestureRecognizer:tapToStomach];
_stomach.userInteractionEnabled = YES;
[tapToStomach release];

UITapGestureRecognizer *tapToFootLeft = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(FootLeft)];
[_footLeft addGestureRecognizer:tapToFootLeft];
_footLeft.userInteractionEnabled = YES;
[tapToFootLeft release];

UITapGestureRecognizer *tapToFootRight = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(FootRight)];
[_footRight addGestureRecognizer:tapToFootRight];
_footRight.userInteractionEnabled = YES;
[tapToFootRight release];

UITapGestureRecognizer *tapToAngra = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Angry)];
[_angry addGestureRecognizer:tapToAngra];
_angry.userInteractionEnabled = YES;
[tapToAngra release];

UITapGestureRecognizer *tapToKnockout = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Knockout)];
[_knockout addGestureRecognizer:tapToKnockout];
_knockout.userInteractionEnabled = YES;
[tapToKnockout release];
}



-(void)Eat
{
    NSLog(@"123");
    _array = [NSMutableArray array];
    NSString *nameString = @"";
    for (NSInteger i = 0; i < 40; i++) {
        if (i < 10) {
            nameString = [NSString stringWithFormat:@"eat_0%ld.jpg", i];
        }else{
            nameString = [NSString stringWithFormat:@"eat_%ld.jpg", i];
        }
        UIImage *image = [UIImage imageNamed:nameString];
        [_array addObject:image];
    }
    _imageView.animationImages = _array;
    _imageView.animationDuration = 2;
    _imageView.animationRepeatCount = 1;
    [_imageView startAnimating];
}

-(void)Fart
{
    NSLog(@"123");
    _array = [NSMutableArray array];
    NSString *nameStr = @"";
    for (NSInteger i = 0; i < 28; i++) {
        if (i < 10) {
            nameStr = [NSString stringWithFormat:@"fart_0%ld.jpg", i];
        }else{
            nameStr = [NSString stringWithFormat:@"fart_%ld.jpg", i];
        }
        UIImage *image = [UIImage imageNamed:nameStr];
        [_array addObject:image];
    }
    _imageView.animationImages = _array;
    _imageView.animationDuration = 2;
    _imageView.animationRepeatCount = 1;
    [_imageView startAnimating];
    
}

-(void)Cymbal
{
    NSLog(@"123");
    _array = [NSMutableArray array];
    NSString *nameStr = @"";
    for (NSInteger i = 0; i < 12; i++) {
        if (i < 10) {
            nameStr = [NSString stringWithFormat:@"cymbal_0%ld.jpg", i];
        }else{
            nameStr = [NSString stringWithFormat:@"cymbal_%ld.jpg", i];
        }
        UIImage *image = [UIImage imageNamed:nameStr];
        [_array addObject:image];
    }
    _imageView.animationImages = _array;
    _imageView.animationDuration = 2;
    _imageView.animationRepeatCount = 1;
    [_imageView startAnimating];
    
}


-(void)Pie
{
    NSLog(@"123");
    _array = [NSMutableArray array];
    NSString *nameStr = @"";
    for (NSInteger i = 0; i < 24; i++) {
        if (i < 10) {
            nameStr = [NSString stringWithFormat:@"pie_0%ld.jpg", i];
        }else{
            nameStr = [NSString stringWithFormat:@"pie_%ld.jpg", i];
        }
        UIImage *image = [UIImage imageNamed:nameStr];
        [_array addObject:image];
    }
    _imageView.animationImages = _array;
    _imageView.animationDuration = 2;
    _imageView.animationRepeatCount = 1;
    [_imageView startAnimating];
    
}

-(void)Drink
{
    NSLog(@"123");
    _array = [NSMutableArray array];
    NSString *nameStr = @"";
    for (NSInteger i = 0; i < 81; i++) {
        if (i < 10) {
            nameStr = [NSString stringWithFormat:@"drink_0%ld.jpg", i];
        }else{
            nameStr = [NSString stringWithFormat:@"drink_%ld.jpg", i];
        }
        UIImage *image = [UIImage imageNamed:nameStr];
        [_array addObject:image];
    }
    _imageView.animationImages = _array;
    _imageView.animationDuration = 5;
    _imageView.animationRepeatCount = 1;
    [_imageView startAnimating];
    
}

-(void)Scratch
{
    NSLog(@"123");
    _array = [NSMutableArray array];
    NSString *nameStr = @"";
    for (NSInteger i = 0; i < 56; i++) {
        if (i < 10) {
            nameStr = [NSString stringWithFormat:@"scratch_0%ld.jpg", i];
        }else{
            nameStr = [NSString stringWithFormat:@"scratch_%ld.jpg", i];
        }
        UIImage *image = [UIImage imageNamed:nameStr];
        [_array addObject:image];
    }
    _imageView.animationImages = _array;
    _imageView.animationDuration = 4;
    _imageView.animationRepeatCount = 1;
    [_imageView startAnimating];
    
}

-(void)Stomach
{
    NSLog(@"123");
    _array = [NSMutableArray array];
    NSString *nameStr = @"";
    for (NSInteger i = 0; i < 34; i++) {
        if (i < 10) {
            nameStr = [NSString stringWithFormat:@"stomach_0%ld.jpg", i];
        }else{
            nameStr = [NSString stringWithFormat:@"stomach_%ld.jpg", i];
        }
        UIImage *image = [UIImage imageNamed:nameStr];
        [_array addObject:image];
    }
    _imageView.animationImages = _array;
    _imageView.animationDuration = 2;
    _imageView.animationRepeatCount = 1;
    [_imageView startAnimating];
    
}


-(void)FootRight
{
    NSLog(@"123");
    _array = [NSMutableArray array];
    NSString *nameStr = @"";
    for (NSInteger i = 0; i < 30; i++) {
        if (i < 10) {
            nameStr = [NSString stringWithFormat:@"footRight_0%ld.jpg", i];
        }else{
            nameStr = [NSString stringWithFormat:@"footRight_%ld.jpg", i];
        }
        UIImage *image = [UIImage imageNamed:nameStr];
        [_array addObject:image];
    }
    _imageView.animationImages = _array;
    _imageView.animationDuration = 1;
    _imageView.animationRepeatCount = 1;
    [_imageView startAnimating];
    
    
}

-(void)FootLeft
{
    NSLog(@"123");
    _array = [NSMutableArray array];
    NSString *nameStr = @"";
    for (NSInteger i = 0; i < 30; i++) {
        if (i < 10) {
            nameStr = [NSString stringWithFormat:@"footLeft_0%ld.jpg", i];
        }else{
            nameStr = [NSString stringWithFormat:@"footLeft_%ld.jpg", i];
        }
        UIImage *image = [UIImage imageNamed:nameStr];
        [_array addObject:image];
    }
    _imageView.animationImages = _array;
    _imageView.animationDuration = 1;
    _imageView.animationRepeatCount = 1;
    [_imageView startAnimating];
    
}

-(void)Angry
{
    _array = [NSMutableArray array];
    //每次图片的名字
    NSString *nameString = @"";//
    //循环创建image对象添加到数组里
    for (NSInteger i = 0; i <= 25; i++) {
        if (i < 10) {
            nameString = [NSString stringWithFormat:@"angry_0%ld.jpg", i];
        }else{
            nameString = [NSString stringWithFormat:@"angry_%ld.jpg", i];
        }
        //chuang创建图片对象
        UIImage *image = [UIImage imageNamed:nameString];
        [_array addObject:image];
    }
    //将图片数组赋值给imageView*********
    _imageView.animationImages = _array;
    //播放所有图片的时间
    _imageView.animationDuration = 2;
    //本次图片重复次数默认一直播放
    _imageView.animationRepeatCount = 1;
    //开始播放
    [_imageView startAnimating];
    
}

-(void)Knockout
{
    NSLog(@"123");
    flag += 1;
    _array = [NSMutableArray array];
    NSString *nameStr = @"";
    if (flag < 5) {
        for (NSInteger i = 0; i < 10; i++) {
            nameStr = [NSString stringWithFormat:@"knockout_0%ld.jpg", i];
            UIImage *image = [UIImage imageNamed:nameStr];
            [_array addObject:image];
        }
        
        _imageView.animationImages = _array;
        _imageView.animationDuration = 1;
        _imageView.animationRepeatCount = 1;
        [_imageView startAnimating];
        
    }else{
        for (NSInteger i = 0; i < 81; i++) {
            if (i < 10) {
                nameStr = [NSString stringWithFormat:@"knockout_0%ld.jpg", i];
            }else{
                nameStr = [NSString stringWithFormat:@"knockout_%ld.jpg", i];
            }
            UIImage *image = [UIImage imageNamed:nameStr];
            [_array addObject:image];
        }
        _imageView.animationImages = _array;
        _imageView.animationDuration = 7;
        _imageView.animationRepeatCount = 1;
        [_imageView startAnimating];
        flag = 0;
        
    }
    
    
    
    
}















- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
